package com.shujia.wyh.day16;

/*
        删除功能
            public StringBuffer deleteCharAt(int index)
            public StringBuffer delete(int start,int end)

 */
public class StringBufferDemo3 {
    public static void main(String[] args) {
        StringBuffer sb = new StringBuffer("helloworldjavabigdata");
        System.out.println("sb:" + sb);
        System.out.println("实际存储字符的个数为："+sb.length());
        System.out.println("==============================================");
        //public StringBuffer deleteCharAt(int index)删除char在这个序列中的指定位置。 该序列缩短了一个char 。
        sb.deleteCharAt(9);
        System.out.println("sb:" + sb);
        System.out.println("实际存储字符的个数为："+sb.length());
//        sb.deleteCharAt(22); //StringIndexOutOfBoundsException
//        sb.deleteCharAt(20);
        System.out.println("==============================================");
        //public StringBuffer delete(int start,int end)
        //删除此序列的子字符串中的字符。 子串开始于指定start并延伸到字符索引end - 1
        //[start,end)
        sb.delete(9,13);
        System.out.println("sb:" + sb);
        System.out.println("实际存储字符的个数为："+sb.length());
        System.out.println("==============================================");
//        sb.delete(17,18); //StringIndexOutOfBoundsException 前面第一个参数的索引必须要存在
        sb.delete(10,20);
        System.out.println("sb:" + sb);
        System.out.println("实际存储字符的个数为："+sb.length());
        System.out.println("==============================================");
        //需求：我想删除此刻 helloworlb 删除he后面的所有字符
        sb.delete(2,sb.length());
        System.out.println("sb:" + sb);
        System.out.println("实际存储字符的个数为："+sb.length());

    }
}
